<?php
namespace app\index\controller;

use think\Controller;
use think\Db;
class LeaderIncome extends Common{


    //基础信息类页面渲染
    public function index(){
        return $this->fetch();
    }
    //添加界面
    public function add(){
        //获取基础信息
        $info = Db('user')
        ->select();
        $this->assign('user', $info);
        
        return $this->fetch();
    }
    //编辑界面
    public function edit(){
        $id = request()->param('id');

        //获取基础信息
        $info = Db('user')
            ->select();
        $this->assign('user', $info);

        $info = Db('person_annual_wage')
            ->where('id','=',$id)
            ->find();

        $this->assign('info', $info);
        return $this->fetch();
    }
    //基础信息表格数据渲染
    public function getLeaderIncome(){
        $page = request()->param('page');
        $limit = request()->param('limit');
        $start = ($page-1) * $limit;
        $modoules = input('name');
        $value =input('job_number');

        $info = Db('person_annual_wage')
            ->join('user', ' person_annual_wage.user_id = user.id ')
            ->where('person_annual_wage.isdelete',0);

        $modules = input("modules");
        $value =input("value");

        if( $value && $modules){
            $info =  $info ->where($modules,'LIKE','%'.$value .'%');
        }

        $IncomeList = $info->limit($start,$limit)->select();
        $count = $info->limit($start,$limit)->count();


       /**  每月发放部分
        * a.岗位工资：对应岗位等级，每级别一标准;
        * b.薪级工资：对应岗位等级及薪级，每级别一标准;
        * c.保留福利补贴：对应岗位等级，每级别一标准;
        * d.岗位奖励绩效工资:对应校内岗位，每级别一标准
        * e.基本业绩奖励：对应校内岗位，每级别一标准
        * f.特殊岗位津贴：个别人享受
        * g.物业补贴：对应校内岗位，每级别一标准
        * h.文明奖：每人数值不同
        * i.独生子女费：每人数值不同
        * j.少数民族补贴：仅回族享受
        * k.卫生费：仅女性享受
        * l.博士补贴：仅博士享受，数值不同
        * m.教授补贴：仅非博士的教授享受
        * n.租房补贴：仅引进博士享受
        * o.车补：仅副厅级以上领导享受
        * p.补工资：临时性补发工资
        *②扣除部分：
        *a.住房公积金：从工资中代扣住房公积金
        *b.医保金：从工资中代扣医保金
        *c.养老保险个人（企业）：从工资中代扣企业养老保险金
        *d.养老保险个人：从工资中代扣事业养老保险金
        *e.职业年金个人：从工资中代扣职业年金
        *f.扣个人所得税：从工资中代扣个人所得税
        *g.扣房租：从工资中代扣租房房租
        *h.扣物业：从工资中代扣物业费
        *i.扣水电；从工资中代扣水电费
        *j.扣工资，临时性扣工资项
        *③单独发放收入
        *a.取暖费：每年11月根据职务职称发放的取暖费
        *b.目标考核奖：年度发放的目标考核奖
        *c.全国文明城市奖：年度发放的全国文明城市奖
        *d.绩效工资：年度发放的绩效工资
        */
        //var_dump($IncomeList[1]);
        $array = array();
        if($IncomeList != null){
            foreach($IncomeList as $value){
                $msg = array(
                    //序号
                    'id' => $value['id'],
                    //用户id
                    'user_id' => $value['user_id'],
                    //用户名字
                    'name' => $value['name'],
                    //工号
                    'job_number' => $value['job_number'],
                    //发放日期
                    'wage_date' => $value['wage_date'],

                    //每月应发部分
                    'income' =>
                        $value['job_salary']+
                        $value['job_level_salary']+
                        $value['retention_benefit_subsidy']+
                        $value['job_reward_performance_salary']+
                        $value['basic_performance_award']+
                        $value['special_post_allowance']+
                        $value['property_subsidy']+
                        $value['civilization_award']+
                        $value['one_child_fee']+
                        $value['ethnic_minorities_subsidy']+
                        $value['public_sanitation_fee']+
                        $value['doctor_subsidy']+
                        $value['professor_subsidy']+
                        $value['rental_subsidy']+
                        $value['car_supplement']+
                        $value['supplementary_salary'],
                    //扣除部分
                    'deduction' =>
                        $value['housing_provident_fund']+
                        $value['medical_insurance_fund']+
                        $value['endowment_insurance_individual_enterprise']+
                        $value['endowment_insurance_individual']+
                        $value['occupational_annuity_individual']+
                        $value['deduction_of_individual_income_tax']+
                        $value['deduction_of_rent']+
                        $value['withholding_property']+
                        $value['deduction_of_hydropower']+
                        $value['deduction_of_wages'],
                    //单独发放收入
                    'separately' =>
                        $value['heating_fee']+
                        $value['target_assessment_award']+
                        $value['national_civilized_city_award']+
                        $value['merit_pay']
                );
                array_push($array,$msg);
            }
        }



        
        $msg = [
            'code' => 0,
            'msg' => '查询成功',
            'data' => $array,
            'count' => $count
        ];
        
        echo json_encode($msg);
    }

    public function addPost(){
        $id = Db('person_annual_wage')->order('id desc')->limit(1)->find()['id'] +1;
        $status=Db('person_annual_wage')
        ->insert([
            "id" =>$id,
            "wage_date" => request()->param("wage_date"),
            "user_id" =>request()->param("user_id"),
            "job_salary" =>request()->param("job_salary"),
            "job_level_salary" =>request()->param("job_level_salary"),
            "retention_benefit_subsidy" =>request()->param("retention_benefit_subsidy"),
            "job_reward_performance_salary" =>request()->param("job_reward_performance_salary"),
            "basic_performance_award" =>request()->param("basic_performance_award"),
            "special_post_allowance" =>request()->param("special_post_allowance"),
            "property_subsidy" =>request()->param("property_subsidy"),
            "civilization_award" =>request()->param("civilization_award"),
            "one_child_fee" =>request()->param("one_child_fee"),
            "ethnic_minorities_subsidy" =>request()->param("ethnic_minorities_subsidy"),
            "public_sanitation_fee" =>request()->param("public_sanitation_fee"),
            "doctor_subsidy" =>request()->param("doctor_subsidy"),
            "professor_subsidy" =>request()->param("professor_subsidy"),
            "rental_subsidy" =>request()->param("rental_subsidy"),
            "car_supplement" =>request()->param("car_supplement"),
            "supplementary_salary" =>request()->param("supplementary_salary"),
            "housing_provident_fund" =>request()->param("housing_provident_fund"),
            "medical_insurance_fund" =>request()->param("medical_insurance_fund"),
            "endowment_insurance_individual_enterprise" =>request()->param("endowment_insurance_individual_enterprise"),
            "endowment_insurance_individual" =>request()->param("endowment_insurance_individual"),
            "occupational_annuity_individual" =>request()->param("occupational_annuity_individual"),
            "deduction_of_individual_income_tax" =>request()->param("deduction_of_individual_income_tax"),
            "deduction_of_rent" =>request()->param("deduction_of_rent"),
            "withholding_property" =>request()->param("withholding_property"),
            "deduction_of_hydropower" =>request()->param("deduction_of_hydropower"),
            "deduction_of_wages" =>request()->param("deduction_of_wages"),
            "heating_fee" =>request()->param("heating_fee"),
            "target_assessment_award" =>request()->param("target_assessment_award"),
            "national_civilized_city_award" =>request()->param("national_civilized_city_award"),
            "merit_pay" =>request()->param("merit_pay")
        ],true);
        $status1 = Db('issue_date')->insert([
            "wage_date" => request()->param("wage_date")
        ],true);

        if($status){
            if($status1){
                $this->success('添加成功');
            }else{
                $this->error('添加失败,issue_date');
            }
        }else{
            $this->error('添加失败，person_annual_wage');
        }


    }

    public function editPost(){
        $id = request()->param('id');
        $status=Db('person_annual_wage')
            ->where('id','=',$id)
            ->update([
                "user_id" =>request()->param("user_id"),
                "job_salary" =>request()->param("job_salary"),
                "job_level_salary" =>request()->param("job_level_salary"),
                "retention_benefit_subsidy" =>request()->param("retention_benefit_subsidy"),
                "job_reward_performance_salary" =>request()->param("job_reward_performance_salary"),
                "basic_performance_award" =>request()->param("basic_performance_award"),
                "special_post_allowance" =>request()->param("special_post_allowance"),
                "property_subsidy" =>request()->param("property_subsidy"),
                "civilization_award" =>request()->param("civilization_award"),
                "one_child_fee" =>request()->param("one_child_fee"),
                "ethnic_minorities_subsidy" =>request()->param("ethnic_minorities_subsidy"),
                "public_sanitation_fee" =>request()->param("public_sanitation_fee"),
                "doctor_subsidy" =>request()->param("doctor_subsidy"),
                "professor_subsidy" =>request()->param("professor_subsidy"),
                "rental_subsidy" =>request()->param("rental_subsidy"),
                "car_supplement" =>request()->param("car_supplement"),
                "supplementary_salary" =>request()->param("supplementary_salary"),
                "housing_provident_fund" =>request()->param("housing_provident_fund"),
                "medical_insurance_fund" =>request()->param("medical_insurance_fund"),
                "endowment_insurance_individual_enterprise" =>request()->param("endowment_insurance_individual_enterprise"),
                "endowment_insurance_individual" =>request()->param("endowment_insurance_individual"),
                "occupational_annuity_individual" =>request()->param("occupational_annuity_individual"),
                "deduction_of_individual_income_tax" =>request()->param("deduction_of_individual_income_tax"),
                "deduction_of_rent" =>request()->param("deduction_of_rent"),
                "withholding_property" =>request()->param("withholding_property"),
                "deduction_of_hydropower" =>request()->param("deduction_of_hydropower"),
                "deduction_of_wages" =>request()->param("deduction_of_wages"),
                "heating_fee" =>request()->param("heating_fee"),
                "target_assessment_award" =>request()->param("target_assessment_award"),
                "national_civilized_city_award" =>request()->param("national_civilized_city_award"),
                "merit_pay" =>request()->param("merit_pay")
            ]);

        if($status){
            $this->success('更新成功');
        }else{
            $this->error('更新失败');
        }
    }
    //用户页面删除信息处理
    public function remove(){
        if(request()->param('id')){
            $id     = request()->param('id'); //获取id
            $status = Db('person_annual_wage')
                ->where('id',$id)
                ->update([
                    'isdelete' =>"1"
                ]);
            if($status){
                $this->success('删除成功');
            }else{
                $this->error('删除失败');
                exit;
            }
        }
    }
    //用户页面删除选中信息
    public function removeselected(){
        //接收参数
        $map = input();

        $IDs=implode(',', $map['id']);
        $where = 'id in('.$IDs.')';

        $list = Db('person_annual_wage')
            ->where($where)
            ->update([
                'isdelete' =>"1"
            ]);
        if($list!==false) {
            $this->success('删除成功');
        }else{
            $this->error( '删除失败');
        }
    }



    


	
}